// EmotionIcons4Blogger
// This Script is modified by [maTT cHEn] from [Blogger EmoIcon] that developed by [billconan].
// 
// [Blogger EmoIcon][billconan] http://billconan.blogspot.com/2007/03/blogger.html
// [EmotionIcons4Blogger][maTT cHEn] http://mattchen.info/2009/06/emotion-icons-for-blogger.html
//
// Code Hosting at http://emotion-icons-for-blogger.googlecode.com
//
// Bookmarklet
/*
javascript:if(document.getElementById('EmotionIcons4Blogger')){alert('EmotionIcons4Blogger Panel has been opened!');}else{var myDomain = document.domain;if((myDomain=='draft.blogger.com')||(myDomain=='www.blogger.com')){var addScript=document.createElement('script');addScript.src='http://emotion-icons-for-blogger.googlecode.com/files/panel.js';addScript.type='text/javascript';void(document.getElementsByTagName('head')[0].appendChild(addScript));}else{alert('EmotionIcons4Blogger just worked with Blogger!');}}
*/

var tuzkiIconURL = new Array(
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon1.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon2.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon3.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon4.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon5.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon6.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon7.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon8.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon9.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon10.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon11.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon12.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon13.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon14.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon15.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon16.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon17.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon18.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon19.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon20.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon21.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon22.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon23.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon24.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon25.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon26.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon27.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon28.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon29.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon30.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon31.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon32.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon33.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon34.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon35.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon36.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon37.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon38.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon39.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon40.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon41.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon42.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon43.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon44.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon45.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon46.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon47.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon48.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon49.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon50.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon51.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon52.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon53.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon54.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon55.gif',
	'http://emotion-icons-for-blogger.googlecode.com/files/tuzki-icon56.gif');

var insertTextarea;

// Usage: insertAtCursor(document.formName.fieldName, 'this value');
function insertAtCursor(myField, myValue) {
	// IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	// Mozilla & Netscape support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

function addIcon(imageSrc) {
	//if (insertTextarea) insertTextarea.value+='<img style="border-width:0px;padding:0" src="'+imageSrc+'"/>';
	if (insertTextarea) insertAtCursor(insertTextarea,'<img style="border-width:0px;padding:0" src="'+imageSrc+'"/>');
}

function generateInnerHTML() {
	var result='';
	for (var i=0;i<tuzkiIconURL.length;++i) {
		result+='<img onclick="javascript:addIcon(this.src);" src="'+tuzkiIconURL[i]+'"/>';
	}
	return ''+result+'';
}

function removePanel() {
	// Remove EmotionIcons4Blogger Panel
	var child = document.getElementById('EmotionIcons4BloggerPanel');
	var parent = document.getElementById('subnav');
	parent.removeChild(child);
	// Remove EmotionIcons4Blogger JS
	var head = document.getElementsByTagName("head")[0];
	var scriptToRemove = document.getElementById('EmotionIcons4BloggerJS');
	if (scriptToRemove) {
		head.removeChild(scriptToRemove);
		alert('EmotionIcons4Blogger Removed!');
	} else {
		alert('EmotionIcons4Blogger already been removed!');
	}

}

var copyright='<a href="http://mattchen.info/2009/06/emotion-icons-for-blogger.html" target="_blank">EmotionIcons4Blogger</a> is modified from <a href="http://billconan.blogspot.com/2007/03/blogger.html" target="_blank">Blogger EmoIcon</a> by <a href="http://mattchen.info/" target="_blank">maTT cHEn</a>.'
var insertPanel;
if(insertPanel=document.getElementById('subnav')) {
	var myDomain = document.domain;
	if (myDomain=='draft.blogger.com') insertTextarea = document.getElementById('postingHtmlBox');
	if (myDomain=='www.blogger.com') insertTextarea = document.getElementById('textarea')
	if (insertPanel) {
		insertPanel.innerHTML+='<div style="position:absolute;left:735px;top:140px;width:260px;z-index:20;border:1px solid;" id="EmotionIcons4BloggerPanel" align="center"><div align="right"><a href="#" onclick="javascript:removePanel();">[x]</a></div><h2>EmotionIcons4Blogger</h2><h5><font color="red">!! Only worked with [Edit HTML] Mode !!</font></h5><hr>'+generateInnerHTML()+'<hr>'+copyright+'<div align="right"><a href="#" onclick="javascript:removePanel();">[x]</a></div></div>';
	} else {
		alert('***ERROR***\nCan not insert the EmotionIcons4Blogger Panel!');
	}
} else {
	alert('EmotionIcons4Blogger only worked with Blogger!');
}







